/*
 * Copyright 2012-2025 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.assertj.tests.core.internal.objectarrays;

import static org.assertj.core.error.ShouldContainOnlyNulls.shouldContainOnlyNulls;
import static org.assertj.core.util.Arrays.array;
import static org.assertj.core.util.FailureMessages.actualIsNull;
import static org.assertj.core.util.Lists.list;
import static org.assertj.tests.core.util.AssertionsUtil.assertThatAssertionErrorIsThrownBy;
import static org.assertj.tests.core.util.AssertionsUtil.expectAssertionError;
import static org.mockito.Mockito.verify;

import java.util.List;

import org.junit.jupiter.api.Test;

/**
 * @author Billy Yuan
 */
class ObjectArrays_assertContainsOnlyNulls_Test extends ObjectArraysBaseTest {
  private Object[] actual = array();

  @Test
  void should_pass_if_actual_contains_null_once() {
    arrays.assertContainsOnlyNulls(INFO, new Object[] { null });
  }

  @Test
  void should_pass_if_actual_contains_null_more_than_once() {
    arrays.assertContainsOnlyNulls(INFO, array(null, null, null));
  }

  @Test
  void should_fail_if_actual_is_null() {
    assertThatAssertionErrorIsThrownBy(() -> arrays.assertContainsOnlyNulls(INFO, null)).withMessage(actualIsNull());
  }

  @Test
  void should_fail_if_actual_is_empty() {
    // WHEN
    expectAssertionError(() -> arrays.assertContainsOnlyNulls(INFO, actual));
    // THEN
    verify(failures).failure(INFO, shouldContainOnlyNulls(actual));
  }

  @Test
  void should_fail_if_actual_contains_null_and_non_null_elements() {
    // GIVEN
    var actual = array(null, null, "person");
    List<String> nonNulls = list("person");
    // WHEN
    expectAssertionError(() -> arrays.assertContainsOnlyNulls(INFO, actual));
    // THEN
    verify(failures).failure(INFO, shouldContainOnlyNulls(actual, nonNulls));
  }

  @Test
  void should_fail_if_actual_contains_non_null_elements_only() {
    // GIVEN
    var actual = array("person", "person2");
    List<String> nonNulls = list("person", "person2");
    // WHEN
    expectAssertionError(() -> arrays.assertContainsOnlyNulls(INFO, actual));
    // THEN
    verify(failures).failure(INFO, shouldContainOnlyNulls(actual, nonNulls));
  }
}
